package com.weixin.engine.design.chain;

import java.util.HashMap;
import java.util.Map;

/**
 * 客户端代码
 *
 * @author wangchunhui
 * @date 2023/7/20 10:04
 */
public class TestChain {
    public static void main(String[] args) {
        Request request = new Request();
        request.setApiKey("valid_api_key");
        Map<String, String> parameters = new HashMap<>();
        parameters.put("param1", "value1");
        parameters.put("param2", "value2");
        request.setParameters(parameters);

        // 创建责任链
        Handler apikeyHandler = new ApiKeyValidationHandler();
        Handler requestValidationHandler = new RequestValidationHandler();
        Handler requestSigningHandler = new RequestSigningHandler();
        Handler apiCallHandler = new ApiCallHandler();
        Handler responseParsingHandler = new ResponseParsingHandler();

        apikeyHandler.setNext(requestValidationHandler);
        requestValidationHandler.setNext(requestSigningHandler);
        requestSigningHandler.setNext(apiCallHandler);
        apiCallHandler.setNext(responseParsingHandler);

        // 启动责任链处理
        apikeyHandler.handleRequest(request);
    }
}
